package com.wm.task.view;

import com.wm.task.dao.MarketDAO;
import com.wm.task.vo.User;

public class MainViewII extends BaseView{
    private boolean bl = true;
    private MarketDAO marketDAO = new MarketDAO();
    private User user;

    public MainViewII() {
    }

    public MainViewII(User user) {
        this.user = user;
    }

    public void show() {
        while (true) {
            printMenu();
            String choice = getChoice();
            if (choice.equals("0")) {
                handleQuit();
                break;
            }
            handleChoice(choice);

            if(!bl){
                break;
            }

        }
    }

    @Override
    protected void handleChoice(String choice) {
        switch (choice) {
            case "1"://商品列表

                break;
            case "2"://购物车

                break;
            case "3"://订单列表

                break;
            case "4"://修改密码
                changePass();
                break;


        }
    }

    private void changePass() {
        System.out.println("===修改密码===");
        String pass;
        while (true) {
            System.out.print("请输入新密码:");
            pass = sc.next();
            System.out.print("请再次输入新密码:");
            if (pass.equals(sc.next())) {
                break;
            } else {
                System.out.println("两次密码不一致,请重新输入");
            }
        }
        marketDAO.changePass(pass,user);

        bl = false;

    }

    @Override
    protected String getTitle() {
        return "万码商城(登录用户:"+user.getName()+")";
    }

    @Override
    protected String[] getMenus() {
        String[] menus = {"商品列表","购物车","订单列表","修改密码","退出"};
        return menus;
    }
}
